<?php
/**
 * CK 开发框架
 * User: Clake
 * Date: 17/1/14
 * Time: 16:17
 */

namespace CK\Util;


use CK\Core\Component;

/**
 * 运行时类
 * Class Runtime
 *
 * @package CK\Util
 */
class Runtime extends Component {
    private $_start_time;
    private $_end_time;
    private $_diff_time;

    /**
     * 开始计时
     */
    public function start() {
        $this->_start_time = microtime(true);
    }

    /**
     * 结束计时并返回时间差
     * @return mixed
     */
    public function end() {
        $this->_end_time = microtime(true);
        $this->_diff_time = $this->_end_time - $this->_start_time;
        return $this->_diff_time;
    }

    /**
     * 结束计时并打印时间差
     */
    public function endAndOutput() {
        $diff = $this->end();
        echo $diff;
    }
}